'use strict';

const { extendDefaultPlugins } = require('svgo');
const { svgoAction } = require('./svgo');

function svgOptimize(input, output, removeFill, removeStroke) {

  function getRemoveAttrs() {
    let attrs = [];
    if (removeFill) {
      attrs.push('fill');
    }
    if (removeStroke) {
      attrs.push('stroke');
    }
    if (attrs.length > 0) {
      return { name: 'removeAttrs', params: { attrs } };
    }
  }
  let ra = getRemoveAttrs();
  let plugins = [
    'convertStyleToAttrs',
    {
      name: 'removeUselessStrokeAndFill',
      active: false
    }
  ];
  if (ra) {
    plugins.push(ra);
  }

  const config = {
    multipass: true, // boolean. false by default
    plugins: extendDefaultPlugins(plugins)
  };

  svgoAction(input, output, config);
}

exports.svgOptimize = svgOptimize;